/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "Modbus.h"
#include "ModbusMasterApp.h"
#include "ModbusSlaveApp.h"
#include "ModbusUserConfig.h"



/*******************************************************************************
 * Prototypes
 ******************************************************************************/


/*******************************************************************************
 * Variables
 ******************************************************************************/


/*******************************************************************************
 * Code
 ******************************************************************************/


/*!
 * @brief Main function
 */
int main(void)
{
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();

#ifdef MODBUS_SLAVE_USED
	Slave0_InitPort(SLAVE_PORT0, MODBUS_SLAVE0_ADDRESS);
#endif

#ifdef MODBUS_MASTER_USED
	MB_Init(MASTER_PORT0);
	Master0_InitPort(MASTER_PORT0);
#endif

  while (1)
  {
#ifdef MODBUS_SLAVE_USED
    ModbusSlaveMainProcess(SLAVE_PORT0);
    ModbusSlavePollSend(SLAVE_PORT0);
    ModbusNet1SlaveAPP();
#endif
    
#ifdef MODBUS_MASTER_USED
    ModbusNet1MasterAPP(MASTER_PORT0);
    ModbusMasterSendMessage(MASTER_PORT0);
    ModbusMasterMainReceive(MASTER_PORT0);
#endif
  }
}
